﻿var ns;
var app = new Vue({
    el: '#app',
    data: {
        userinfo: { headimg: '../image/default.png', username: '用户', phonenumber: '' }
    },
    methods: {
        get_data: function() {
            var that = this;
            api.getPrefs({ key: 'uid' }, function(ret, err) {
                if (ret.value) {
                    api.getPrefs({ key: 'username' }, function(ret, err) {
                        if (ret.value && ret.value != '') {
                            that.userinfo.username = ret.value;
                        }
                    });
                    api.getPrefs({ key: 'headimg' }, function(ret, err) {
                        if (ret.value && ret.value != '') {
                            that.image_cache(ret.value);
                        }
                    });
                    api.getPrefs({ key: 'phonenumber' }, function(ret, err) {
                        if (ret.value && ret.value != '') {
                            that.userinfo.phonenumber = ret.value;
                        }
                    });
                }
            });
        },
        open_mycenter: function() {
            var that = this;
            ns.openWin('gerenzhongxin_frm', '个人中心');
        },
        image_cache: function(url) {
            var that = this;
            that.userinfo.headimg = url;
            api.imageCache({
                url: url
            }, function(ret, err) {
                if (ret.status) {
                    that.userinfo.headimg = ret.url;
                }
            });
        },
        open_setting: function() {
            var that = this;
            ns.openWin('setting_frm', '系统设置');
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.get_data();
    api.addEventListener({
        name: 'changecentersuccess'
    }, function() {
        app.get_data();
    });
}
